<?php
/* 
 * Copyright (c) 2018-2021   All rights reserved.
 * 
 * 创建时间：2021-05-15 13:10
 *
 * 项目：upload  -  $  - index.php
 *
 * 作者：liwei 
 */
?>

<div class="page page-admin">
    <div class="navbar page-admin-navbar adminbar navbar-bgcolor-red">
        <div class="navbar-inner">
            <div class="left">
                <?=\lev\widgets\adminModulesNav\adminModulesNav::buttonHtm()?>
                <a class="link tooltip-init" href="javascript:window.history.back();" data-tooltip="后退">
                    <svg class="icon" aria-hidden="true"><use xlink:href="#fa-back"></use></svg>
                </a>
                <a class="link tooltip-init" href="javascript:window.location.reload();" data-tooltip="刷新">
                    <svg class="icon" aria-hidden="true"><use xlink:href="#fa-refresh"></use></svg>
                </a>
                <a class="link deleteCheckAll">
                    <svg class="icon" aria-hidden="true"><use xlink:href="#fa-trash"></use></svg>
                </a>
            </div>
            <div class="title">
                <?php echo Lev::$app['title']?>
                <tips class="date" style="color:yellow !important;"><?=$tips?></tips>
            </div>
            <div class="right">
                <a class="button button-fill scale9" href="<?php echo Lev::toCurrent(['r'=>'settings/form', 'iden'=>$iden])?>">
                    新增字段
                </a>
                <a class="button button-fill color-black scale9" href="<?php echo Lev::toCurrent(['r'=>'modules'])?>">
                    模块管理
                </a>
                <a class="button button-fill color-yellow scale9" href="<?php echo Lev::toCurrent(['r'=>'settings/export', 'iden'=>$iden])?>">导出</a>
            </div>

            <?php echo \lev\helpers\ModulesHelper::getAdminSubnavHtmsAndBox()?>
        </div>
    </div>

    <div class="page-content">
        <div class="card data-listb">
            <div class="card card-header"><tips>【提示】(输入框名为pwd、password以及Pwd结尾)的字段导出时自动清空内容</tips></div>
            <div class="data-xtable">
                <table><thead><tr>
                        <th class="checkbox-cell tab-center wd30"><input name="ids[]" type="checkbox" onclick="checkedToggle(this,'input[name=\'ids[]\']')"></th>
                        <th class="tab-center wd60">排序</th>
                        <th class="label-cell wd60">模块名称(标识符)</th>
                        <th class="tab-center wd60">表单分步填</th>
                        <th class="label-cell wd60">设置分类</th>
                        <th class="label-cell wd60">输入框标题</th>
                        <th class="label-cell wd60">输入框名(name)</th>
                        <th class="label-cell wd60">输入框类型(type)</th>
                        <th class="label-cell">扩展设置(settings)</th>
                        <th class="label-cell">输入框提示语(placeholder)</th>
                        <th class="tab-center wd60">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php if (!empty($settings)):foreach ($settings as $v):?>
                    <tr>
                        <td class="checkbox-cell tab-center"><input name="ids[]" type="checkbox" value="<?php echo $v['id']?>" autocomplete="off"></td>
                        <td class="tab-center">
                            <input class="dorder setField" type="text" name="displayorder" opid="<?=$v['id']?>" value="<?=$v['displayorder']?>" autocomplete="off">
                        </td>
                        <td class="label-cell">
                            <a href="<?=Lev::toCurrent(['iden'=>$v['moduleidentifier'], 'classify'=>null])?>">
                            <?php echo Lev::arrv([$v['moduleidentifier'],'name'], $modules)?>
                            </a>
                            <p class="date transl">
                                <input class="wd80 setField" type="text" name="moduleidentifier" opid="<?=$v['id']?>" value="<?=$v['moduleidentifier']?>" autocomplete="off">
                            </p>
                        </td>
                        <td class="tab-center">
                            <input class="dorder setField" type="text" name="status" opid="<?=$v['id']?>" value="<?=$v['status']?>" autocomplete="off">
                        </td>
                        <td class="label-cell">

                            <a href="<?=Lev::toCurrent(['iden'=>$v['moduleidentifier'], 'classify'=>$v['classify']])?>">
                                <?php echo Lev::arrv($v['classify'], $setClassify)?>
                            </a>
                            <div class="input input-dropdown date transl">
                                <select class="wd100 setField" name="classify" opid="<?=$v['id']?>" autocomplete="off">
                                    <?php foreach ($setClassify as $_key => $_name) : $slt = $_key == $v['classify'] ? 'selected':''?>
                                        <option value="<?=$_key?>" <?=$slt?>><?=$_name?></option>
                                    <?php endforeach;?>
                                </select>
                            </div>

                        </td>
                        <td class="label-cell">
                            <input class="wd120 setField" type="text" name="title" opid="<?=$v['id']?>" value="<?=$v['title']?>" autocomplete="off">
                        </td>
                        <td class="label-cell">
                            <input class="wd120 setField" type="text" name="inputname" opid="<?=$v['id']?>" value="<?=$v['inputname']?>" autocomplete="off">
                        </td>
                        <td class="label-cell">
                            <p class="date transl"><?php echo Lev::arrv($v['inputtype'], $inputtypes)?></p>
                        </td>
                        <td class="label-cell">
                            <textarea class="set-field setField" name="settings" opid="<?=$v['id']?>" autocomplete="off"><?php echo $v['settings']?></textarea>
                        </td>
                        <td class="label-cell">
                            <textarea class="set-field setField" name="placeholder" opid="<?=$v['id']?>" autocomplete="off"><?php echo $v['placeholder']?></textarea>
                        </td>
                        <td class="tab-center">
                            <a href="<?php echo Lev::toCurrent(['r'=>'settings/form', 'opid'=>$v['id'], 'iden'=>$v['moduleidentifier']])?>">
                            <absxb>编辑</absxb>
                            </a>
                        </td>
                    </tr>
                    <?php endforeach; else:?>
                        <tr><td colspan="22" class="tab-center"><tips>没有数据</tips></td></tr>
                    <?php endif;?>
                    </tbody>
                    <tbody class="addTrVarBox" style="background: rgba(247, 10, 10, 0.1);">
                    <tr>
                        <td class="checkbox-cell tab-center"><input type="checkbox" class="disabled"></td>
                        <td class="tab-center"><input class="dorder" type="text" name="displayorder" value="0"></td>
                        <td class="label-cell">
                            <a href="<?=Lev::toCurrent(['iden'=>$iden])?>">
                            <?php echo $mudInfo['name']?>
                            </a>
                            <p class="date transl"><?=$iden?></p>
                        </td>
                        <td class="tab-center">
                            <input class="dorder" type="text" name="status" value="<?=$isForm ? ($v['status'] ?: 1) : 0?>">
                        </td>
                        <td class="label-cell">

                            <div class="input input-dropdown">
                                <label class="inblk scale9 transl">
                                <input type="text" class="onClassifySlt" style="position: absolute;width:75px;height:18px" name="classifymyself" placeholder="可输入下拉框" title="可输入下拉框" value="<?=Lev::arrv($v['classify'], $setClassify)?>">
                                <select class="wd100 _classify_slt" name="classify" style="height: 24px">
                                    <?php foreach ($setClassify as $_key => $_name) : $slt = $_key == $v['classify'] ? 'selected':''?>
                                        <option value="<?=$_key?>" <?=$slt?>><?=$_name?></option>
                                    <?php endforeach;?>
                                </select>
                                </label>
                            </div>
                            <a class="openPP hiddenx" style="position:absolute;top: 0;right: 5px;" title="新增设置分类" href="<?=Lev::toReRoute(['admin-modules/form', 'opid'=>$mudInfo['id']])?>"><svg class="icon"><use xlink:href="#fa-add"></use></a>

                        </td>
                        <td class="label-cell"><input class="wd120" type="text" name="title"></td>
                        <td class="label-cell"><input class="wd120" type="text" name="inputname"></td>
                        <td class="label-cell">

                            <div class="input input-dropdown">
                                <select class="wd100" name="inputtype">
                                    <?php foreach ($inputtypes as $k => $vit) :?>
                                        <option value="<?=$k?>"><?=$vit?></option>
                                    <?php endforeach;?>
                                </select>
                            </div>

                        </td>
                        <td class="label-cell">
                            <textarea class="set-field" name="settings" autocomplete="off"></textarea>
                        </td>
                        <td class="label-cell">
                            <textarea class="set-field" name="placeholder" autocomplete="off"></textarea>
                        </td>
                        <td class="tab-center">
                            <a class="button-active button button-fill color-red" onclick="doAddTrVar()">新增</a>
                        </td>
                    </tr>
                    </tbody>
                </table>
                <div class="card-footer">
                    <tips>【提示】[表单分步]填为0时为设置项，否则为数据表字段</tips>
                    <div class="flex-box">

                        <?php if ($create_classify) {?>
                        <?php if ($isForm) {?>
                        <a class="button button-fill button-small scale8 openPP Inajax" href="<?=Lev::toReRoute(['settings/quick-create-form', 'id'=>'levmodules', 'iden'=>$iden, 'tabname'=>$create_classify])?>">
                            为数据表【<?=$create_classify?>】快速添加表单字段
                        </a>
                        <?php }?>

                        <a class="button button-fill button-small color-yellow scale8" href="<?=Lev::toReRoute(['form_lev_modules', 'setup'=>7, 'iden'=>$iden, 'id'=>'levmodules', 'create_classify'=>$create_classify, 'opid'=>floatval(Lev::GPv('mudid'))])?>">
                            为设置分类【<?=$create_classify?>】创建表单
                        </a>

                        <?php }?>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>


<script>
jQuery(function () {

    jQuery(document).on('blur', '.onClassifySlt', function () {
        var sval = this.value;
        if (sval === "") return;

        var sltd = false;
        jQuery('._classify_slt option').each(function () {
            if (sval === jQuery(this).text()) {
                sltd = true;
                sval = jQuery(this).attr('value');
                return null;
            }
        });
        if (!sltd) {
            if (jQuery('._classify_slt .myselfop').length > 0) {
                jQuery('._classify_slt .myselfop').attr('value', sval).html(sval);
            }else {
                jQuery('._classify_slt').append('<option class="myselfop red" value="' + sval + '" selected>' + sval + '</option>');
            }
        }
        jQuery('._classify_slt').val(sval);
    });

    jQuery(document).on('change', '._classify_slt', function () {
        setonClassifySlt(jQuery(this).find('option:selected').text());
    });

    !jQuery('.onClassifySlt').val() && jQuery('._classify_slt').find('option:selected').text() &&
    setonClassifySlt(jQuery('._classify_slt').find('option:selected').text());
    function setonClassifySlt(sval) {
        jQuery('.onClassifySlt').val(sval);
    }
});
    function doAddTrVar() {
        showIconLoader();
        jQuery('.addTrVarBox').ajaxSubmit({
            url: '',
            data: {dosubmit:1, _csrf:_csrf, inajax:1, _:Math.random()},
            type:'post',
            dataType: 'json',
            success: function(data){
                hideIconLoader();
                if (parseInt(data.status) >0) {
                    levtoast(data.message);
                    window.setTimeout(function () {
                        window.location = window.location.href;
                    }, 100);
                }else if (data && data.message) {
                    levtoast(data.message, 15000);
                }
                showFormErrors(data.errors, '.addTrVarBox ');
            },
            error: function(data) {
                hideIconLoader();
                errortips(data);
            }
        });
        return false;
    }
</script>